package com.central.apps.handler.inspcriterion;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.central.app.common.base.BaseHandler;
import com.central.app.common.constant.AppConstant;
import com.central.apps.dao.inspection.inspcriterionDao;
import com.central.common.web.PageResult;
import com.central.common.web.Result;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class InspcriterionHandler extends BaseHandler {
    @Autowired
    private inspcriterionDao inspcriterionDao;

    @Override
    public Object operate(String app, String type, Map<String, Object> params) throws Exception {
        if ("inspcriterionApp".equals(app)) {
            if ("getAssetsclassify".equals(type)) {
                //查询不存在点检标准中的资产
                Page<Map<String,Object>> page = new Page<>(1, 10);
                if (MapUtils.getInteger(params, AppConstant.BIZ_QUERY_PAGE) != null && MapUtils.getInteger(params, AppConstant.BIZ_QUERY_LIMIT) != null) {
                    page = new Page<>(MapUtil.getInt(params, AppConstant.BIZ_QUERY_PAGE), MapUtil.getInt(params, AppConstant.BIZ_QUERY_LIMIT));
                }
                IPage<Map<String, Object>> pageInfo = inspcriterionDao.getAssetsclassifyAppList(page);
                return PageResult.<Map<String, Object>>builder().data(pageInfo.getRecords()).code(0).count(pageInfo.getTotal()).build();
            }
        }
        return super.operate(app, type, params);
    }
}
